<%include file="header.mako" />
<%namespace name="app" file="tuttfuncs.mako"/>
<script>
 $(function() {
  % if user:
  $('#end_date').datepicker();
  $('#start_date').datepicker();
  $('#add-depend-dlg').dialog({ autoOpen: false,
                                  height: 250,
                                   title: 'Add Dependency',
                                   width: 575 });
  $('#set-depend-dlg').dialog({ autoOpen: false,
                                  height: 275,
                                   title: 'Set ${project.name} as a Dependency',
                                   width: 350 });

  $('#new-task-dlg').dialog({ autoOpen: false,
                                height: 475,
                                 title: 'New Task',
                                 width: 475 });
  $('#new-task-completed-on').datepicker();
  $('#new-task-start').datepicker();
  % endif
 });
</script>
</head>
<body class="container_16">
<div class="grid_16">
<h2 class="cc">Colorado College - Tutt Library Systems</h2>
<h1>Project: ${project.name}</h1>
<input type="hidden" value="${project.key()}" id="entity-key" />
<input type="hidden" value="project" id="entity-type" />
</div>
<div class="clear"></div>
<div class="grid_8">
<h2>Project Details:</h2>
<table id="projects-table">
<tr>
 <th>Field</th>
 <th>Value</th>
 % if user:
 <th>Action</th>
 % endif  
</tr>
<tr>
 <th>Created on:</th>
 <td>${project.created_on}</td>
 % if user:
 <td>READ ONLY</td>
 % endif 
</tr>
<tr class="alt">
<%
  status = project.get_status()
%>
 <th>Status:</th>
 <td>${status['msg']}</td>
 % if user:
 <td>READ ONLY</td>
 % endif 
</tr>
<tr>
 <th>Start Date</th> 
 <td>${project.start_date.strftime('%m/%d/%Y')}</td>
 % if user:
 <td><input id='start_date' value='${project.start_date.strftime('%m/%d/%Y')}' />
     <button onclick="Update('start_date')">Update</button></td>
 % endif
</tr>
<tr class="alt">
 <th>Planned End Date</th>
 <td>${project.end_date.strftime('%m/%d/%Y')}</td>
 % if user:
 <td>
  <input id="end_date" value="${project.end_date.strftime('%m/%d/%Y')}" />
  <button onclick="Update('end_date')">Update</button>
 </td>
 % endif 
</tr>
<tr>
 <th>Project Dependencies:</th>
 <td>
 <ol>
% for row in project.get_dependencies():
 <li>
 % if hasattr(row,'name'):
	<a href="/project?id=${row.key()}">Project: ${row.name}</a>
 % endif
 % if hasattr(row,'description'):
	<a href="/task?id=${row.key()}">Task: ${row.description}</a>
 % endif
 </a>
 % if user:
 <button onclick="RemoveDependancy('${row.key()}')">Remove</button>
 % endif
 </li> 
% endfor
 </ol>
 </td>
% if user:
 <td><button onclick="$('#add-depend-dlg').dialog('open')">Add Dependancy</button></li> 
% endif
</tr>
<tr class="alt">
 <th>Related Projects</th>
 <td>&nbsp;</td>
% if user:
 <td>
 <button onclick="$('#set-depend-dlg').dialog('open')">Set as a dependency to another Project or Task</button>
 </td>
% endif
</tr>
</table>
</div>
<div class="grid_8">
<h2>Project ${project.name} Tasks</h2>
% if user:
 <button onclick="$('#new-task-dlg').dialog('open')">Add New Task</button>
 <button onclick="#">Add Existing Task</button>
% endif
<table id="tasks-table">
<tr>
  <th>Descriptions</th>
  <th>Start Date</th>
  <th>Estimated Finish Date</th>
  <th>Assigned To</th>
% if user:
  <th>Actions</th>
% endif  
 </tr>
 % for i,task in enumerate(project.get_tasks()):
 % if i%2:
 <tr>
 % else:
 <tr class="alt">
 % endif
   <td><a href="/task?id=${task.key()}">${task.description}</td>
   <td>${task.start_date}</td>
   <td>${task.estimate_finished_date}</td>
   <td>
    <ol>
    % for row in task.get_assignees():
     <li>${row.given}</li>
    % endfor
   </td>
% if user:
   <td><button onclick="RemoveTask('${row.key()}')">Remove</button></td>
% endif   
 </tr>
 % endfor 
</table>
</div>
<div class="clear"></div>
## Dialogs section
% if user:
<div id="add-depend-dlg">
 <h2>Add Dependency to ${project.name}</h2>
 <h3>Projects:</h3>
 <select id="new-depend">
 <optgroup label="Projects">
% for row in all_projects:
 <option value="${row.key()}">${row.name}</option>
% endfor
 </optgroup>
 <optgroup label="Tasks">
% for task in all_tasks:
 <option value="${task.key()}">${task.description}</option>
% endfor
 </optgroup>
 </select>
 <br/>
 <button onclick="AddDependancy()">Add</button>
 <button onclick="$('#add-depend-dlg').dialog('close')">Cancel</button>
</div>
<div id="set-depend-dlg">
 <h2>Set ${project.name} as a Dependency</h2>
 <div id="depend-dlg-cnt">
  <select id="target-depend">
    <optgroup label="Projects">
    % for row in all_projects:
      <option value="${row.key()}">${row.name}</option>
    % endfor
    </optgroup>
    <optgroup label="Tasks">
    % for task in all_tasks:
      <option value="${task.key()}">${task.description}</option>
    % endfor
    </optgroup>
   </select>    
 </div>
 <button onclick="SetAsDependency()">Add</button>
 <button onclick="$('#set-depend-dlg').dialog('close')">Cancel</button>
</div>
${app.new_task_dialog()}
% endif
<%include file="footer.mako" />
